#include<iostream>
#include "math.h"

using namespace std;

/*
P = principal, the initial amount of the loan
I = the annual interest rate (from 1 to 100 percent)
L = length, the length (in years) of the loan, or at least the length over which the loan is amortized.
The following assumes a typical conventional loan where the interest is compounded monthly. First I will define two more variables to make the calculations easier:

J = monthly interest in decimal form = I / (12 x 100)
N = number of months over which loan is amortized = L x 12
M = P * ( J / (1 - (1 + J) ^ -N))
*/

//int main()
void DanielDavilaMortCalc()
{
double P;
double I;
double L;
double J;
double N;
double M;
double H;
double C;
double Q;

cout << "This is a Mortgage Calculator" << endl;
cout << "Please enter the amount of the Loan: ";
cin >> P;
cout << "Please enter the annual Interest Rate (ex 10% = .10): ";
cin >> I;
cout << "Please enter the number of months for the loan: ";
cin >> N;

J = I / (12 * 100);
M = P * (J / (1 - pow(1+J,-N)));

cout << "Your monthly payment is: $" << M << endl;

//// Amortization table
//
//H = P * J; // monthly interest
//C = M - H; // monthly payment minus interest
//Q = P - C; // balance of principal for loan
//P = Q;
//
 	
	system("PAUSE");
	

}